﻿// dllmain.cpp: DllMain 的实现。

#include <vf_pch.h>
namespace logging = boost::log;
namespace keywords = logging::keywords;
namespace expr = logging::expressions;
ATL::CComModule _Module;

class CExampleAddInApp : public CWinApp {
public:
  // 重写
  virtual BOOL InitInstance();
  virtual int ExitInstance();

  DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CExampleAddInApp, CWinApp)
END_MESSAGE_MAP()

CExampleAddInApp theApp;

BOOL CExampleAddInApp::InitInstance() {
  //_CrtSetBreakAlloc(210);
  auto pSink = logging::add_file_log(
      keywords::open_mode = std::ios_base::app,
      keywords::file_name =
          "TG_VFAdapter_%Y-%m-%d.log", /*< file name pattern >*/
      keywords::rotation_size =
          10 * 1024 * 1024, /*< rotate files every 10 MiB... >*/
      keywords::time_based_rotation =
          boost::log::sinks::file::rotation_at_time_point(
              0, 0, 0) /*< ...or at midnight >*/
      ,
      keywords::format =
          (expr::stream << "["
                        << expr::format_date_time<boost::posix_time::ptime>(
                               "TimeStamp", "%H:%M:%S")
                        << "]" << "[" << logging::trivial::severity << "]"
                        << ": " << expr::smessage),
      keywords::auto_flush = true);
  logging::add_common_attributes();

  CoInitialize(NULL);
  return CWinApp::InitInstance();
}

int CExampleAddInApp::ExitInstance() {
  _Module.Term();
  //_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
  //_CrtDumpMemoryLeaks();
  // 进程卸载时,进行com释放
  CoUninitialize();
  return CWinApp::ExitInstance();
}
